package com.jymf.common;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.jymf.model.Users;

import java.util.Iterator;
import java.util.Set;

/**
 * @ClassName: SessionUtil
 * @Description: session通用类
 * @author zyj
 */
public class SessionUtil {

	public static void setSession(HttpServletRequest request,Users staff) throws Exception{
		HttpSession session = request.getSession();
		session.setAttribute("userInfo", staff);
	}
	
	/**
	 * 获取用户信息
	 * @param request
	 * @author zyj
	 */
	public static Users getSession(HttpServletRequest request){
		HttpSession session = request.getSession();
		Users staff = (Users) session.getAttribute("userInfo");
		
		return staff;
	}
	
	/**
	 * 移除session
	 * @return: void
	 * @author zyj
	 */
	public static void removeSession(HttpServletRequest request) throws Exception{
		HttpSession session = request.getSession(true);
		session.removeAttribute("userInfo");
	}

	/**
	 * 判断是否为不做过滤的请求
	 * @param fileUrl
	 * @return
	 * @return: boolean
	 * @date: 2015-6-17 下午10:06:00
	 * @author zyj
	 */
	public static boolean LoginBack(Set<String> noLoginURLList, String servletPath){
		boolean b = false;

		Iterator<String> it = noLoginURLList.iterator();
		while(it.hasNext()){
			String path = it.next();
			if(path!=null&&servletPath!=null&&servletPath.equals(path)){
				return true;
			}
		}
		return b;
	}

}
